package com.example.demo.ai.train;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TrainController {
    @Autowired
    private TrainService trainService;

    @PostMapping("/api/train")
    public ResponseEntity<String> uploadFolderToSsh(@RequestParam("yamlPath") String yamlPath,
                                                    @RequestParam("pyPath") String pyPath) {
        try {
            String path = trainService.executeRemoteCommand(yamlPath,pyPath);
            return ResponseEntity.ok("模型训练成功: " + path);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("模型训练失败: " + e.getMessage());
        }
    }
}
